/**
 * @description: 自定义命令
 * @return { Array}
 */
const directives = [
  {
    key: "loadmore", // select组件加载更多指令
    value: {
      bind(el, binding) {
        const selectDom = el.querySelector(
          ".el-select-dropdown .el-select-dropdown__wrap"
        );
        selectDom.addEventListener("scroll", function() {
          if (
            this.scrollHeight - this.scrollTop <= this.clientHeight &&
            this.scrollTop > 0
          ) {
            binding.value();
          }
        });
      },
    },
  },
  {
    key: "limit", // 限流指令
    value: {
      inserted(el, binding) {
        el.addEventListener("click", (e) => {
          el.style.pointerEvents = "none";
          el.disabled = true;
          setTimeout(() => {
            el.disabled = false;
            el.style.pointerEvents = "auto";
          }, binding.value || 1000);
        });
      },
    },
  },
];

export default directives;
